# -*- coding:utf-8 -*-
"""
# @File : ajax_views.py
# @Author:chen
# @Date : 2023/9/17
# @Desc :
"""
from plan import models
from django.http import JsonResponse

def ajax_customer(request):
    res = {'code': 0,'data': []}
    customer_id = request.GET.get('customer_id')
    #根据前端发送的前端校区id，找出
    customer_obj = models.Customer.objects.filter(id=customer_id).first()
    sku_list = models.SKU.objects.filter(cust=customer_obj).order_by('name')
    for sku in sku_list:
        res['data'].append({
            'id':sku.id,
            'name':sku.name,
        })
    print(res)
    # return JsonResponse({'class_list':class_list})
    return JsonResponse(res)


def ajax_sequence(request):
    back_dic = {'code':200,'errmsg':''}
    if request.method == 'POST':
        pid = request.POST.get('pid')


def ajax_calculate(request):
    back_dic = {'code':0, 'errmsg': 'ok'}
    plan_id = request.GET.get('plan_id')
    plan_obj = models.PlanTable.objects.filter(id=plan_id).first()
    sku_processlinecpa = models.SkuProcessLineCpa.objects.filter(sku=plan_obj.sku,process = plan_obj.work_process,line = plan_obj.line).first()
    sku_capacity = models.Capacity.objects.filter(splc=sku_processlinecpa).first()
    cap = sku_capacity.cap
    back_dic['cap'] = cap
    return JsonResponse(back_dic)

def test_axios(request):
    res = ["刘备","张飞","关羽"]
    return JsonResponse(res,safe=False)